package axht.trade.ui;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import static android.widget.Toast.LENGTH_SHORT;

public class SimpleComponentActivity extends AppCompatActivity {

    private EditText et_simple_number;

    private TextView tv_simple_message;

    private Button btn_simple_submit;

    private ImageView iv_simple_icon;

    private CheckBox cb_simple_basket;

    private CheckBox cb_simple_foot;

    private CheckBox cb_simple_pingpang;

    private RadioGroup rg_simple_sex;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_simple_component);
        //获取组件
        //1 TextView
        tv_simple_message = findViewById(R.id.tv_simple_message);
        tv_simple_message.setText("月夜归醉正在学习中");
        //2 EditText
        et_simple_number = findViewById(R.id.et_simple_number);
        //3 Button
        btn_simple_submit = findViewById(R.id.btn_simple_submit);
        btn_simple_submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(SimpleComponentActivity.this,et_simple_number.getText().toString(),LENGTH_SHORT).show();
            }
        });
        //4 ImageView
        iv_simple_icon = findViewById(R.id.iv_simple_icon);
        iv_simple_icon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //设置背景图片
                iv_simple_icon.setBackgroundResource(android.R.drawable.alert_light_frame);
                //设置前景色
                iv_simple_icon.setImageResource(android.R.drawable.ic_media_pause);
            }
        });
        //5 CheckBox
        cb_simple_basket = findViewById(R.id.cb_simple_basket);
        cb_simple_foot = findViewById(R.id.cb_simple_foot);
        cb_simple_pingpang = findViewById(R.id.cb_simple_pingpang);
        //给cb_simple_foot设置选中状态改变监听
        cb_simple_foot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    Toast.makeText(SimpleComponentActivity.this,"选中了足球", LENGTH_SHORT).show();
                }else {
                    Toast.makeText(SimpleComponentActivity.this,"未选中了足球", LENGTH_SHORT).show();
                }

            }
        });
        //6 RadioGroup/RadioButton
        rg_simple_sex = findViewById(R.id.rg_simple_sex);
        rg_simple_sex.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                //找到选中的radioButton
                RadioButton radioButton = findViewById(checkedId);
                //得到文本
                Toast.makeText(SimpleComponentActivity.this,radioButton.getText().toString(), LENGTH_SHORT).show();
            }
        });

    }

    public void confirm(View view) {
        StringBuffer sb = new StringBuffer();
        if(cb_simple_basket.isChecked()){
            sb.append(cb_simple_basket.getText().toString()).append(" ");
        }
        if(cb_simple_foot.isChecked()){
            sb.append(cb_simple_foot.getText().toString()).append(" ");
        }
        if(cb_simple_pingpang.isChecked()){
            sb.append(cb_simple_pingpang.getText().toString()).append(" ");
        }
        //提示
        Toast.makeText(this,sb.toString(), LENGTH_SHORT).show();
    }
}
